package com.smart.thirteen.resultset;

import com.smart.thirteen.Topic;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowCallbackHandler;
import org.springframework.jdbc.core.SqlRowSetResultSetExtractor;
import org.springframework.jdbc.support.rowset.SqlRowSet;
import org.springframework.test.context.jdbc.Sql;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author junrui.wang
 * @create 2019/10/21
 */
public class ResultSetTest {
    public static void main(String[] args) {
        ApplicationContext ac = new ClassPathXmlApplicationContext("classpath*:com/smart/thirteen/applicationContext-template.xml");
        JdbcTemplate jdbcTemplate = (JdbcTemplate) ac.getBean("jdbcTemplate");

        String sql = "SELECT topic_title, user_id FROM t_topic WHERE user_id=?";
        SqlRowSet result = jdbcTemplate.queryForRowSet(sql, "222");
        while (result.next()){
            System.out.println(result.getString("topic_title"));
        }
    }
}
